<!DOCTYPE html>
<html class="ui-page-login" data-dpr="3" style="font-size:24px;width:100%;height:100%;overflow:hidden;">

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title>login-登录主画面</title>
	<link href="css/mui.min.css" rel="stylesheet" />
	<!-- <link href="css/stylelogin.css" rel="stylesheet" /> -->
	<style>
		div#mid {
			position: fixed;
			margin: 0;
			padding: 0;
			width: 85%;
			left: 1rem;
			bottom: .5rem;
			font-size: 14px;
		}

		img.im {
			width: 100%;
			z-index: 1;
		}

		input#icbx {
			width: 15%;
			margin-top: 1.5rem;
			height: 1rem;
		}

		div#div1 {
			position: fixed;
			top: 0;
			left: 0;
			bottom: 0;
			right: 0;
			z-index: -1;
		}

		div#readpolicy {
			display: inline;
		}

		div#policy {
			margin-top: 3rem;
			margin-left: 1rem;
		}

		textarea#polcontent {
			float: left;
			width: 92%;
			height: 17rem;
			border: solid 1px #f00;
			border-radius: 20px;
			resize: none;
			z-index: 99;
			background-color: #FFFFFF;
		}

		div#div1>img {
			height: 100%;
			width: 100%;
			border: 0;
		}
	</style>

</head>

<body style="margin: 0">
	<div id="mid">
		<img alt="" class="im" id="wxLogin" src="">
		<img alt="" class="im" id="mbLogin" src="">
		<div class="mui-input-row mui-radio" id="readpolicy">
			<input type="checkbox" id="icbx" checked="checked" />
			<a style="color: #212121;">我已阅读并遵守</a>
			<u id="fuwu" style="color: #D50000;">服务许可协议</u>
			<span>&nbsp</span>
			<u id="yinsi" style="color: #D50000;">隐私政策</u>
		</div>
	</div>
	<div id="policy" hidden>
		<textarea id="polcontent" readonly>aaa</textarea>
	</div>
	<div id="div1">
		<img src="">
	</div>
	<script src="js/mui.min.js"></script>
	<script src="js/mui.enterfocus.js"></script>
	<script src="js/common.js"></script>
	<script src="js/app.js"></script>
	<script>
		var login_weixinPage, login_mobilePage;
		mui.init({
			statusBarBackground: '#f7f7f7'
		});
		mui.plusReady(function () {
			//plus.nativeUI.toast(plus.runtime.innerVersion);

			/*var system ={};
			var p = navigator.platform;
			var styleElement = document.getElementById('mid');

			system.Linux7 = p.indexOf("Linux armv7l") == 0;
			if (system.Linux7) {
				//plus.nativeUI.toast(p);
				styleElement.style.marginTop = 24 + 'rem';		
			} else {
				system.Linux = p.indexOf("Linux") == 0;
				if(system.Linux) {
					styleElement.style.marginTop = 29 + 'rem';		
				}
				system.iPhone = p.indexOf("iPhone") == 0;
				if(system.iPhone) { 
					styleElement.style.marginTop = 22 + 'rem';			
				}
				//system.Win = p.indexOf("Win") == 0;
			}*/

			plus.screen.lockOrientation("portrait-primary");
			var settings = app.getSettings();
			var state = app.getState();

			/* var wxPage = plus.webview.getWebviewById("login_weixin");
			if (!wxPage) {
				wxPage = mui.preload({
					"id": 'login_weixin',
					"url": 'login_weixin.html'
				});
			};
			var toWxPage = function () {
				//使用定时器的原因：
				//可能执行太快，login_weixin页面loaded事件尚未触发就执行自定义事件，此时必然会失败
				setTimeout(function() {
					mui.openWindow({
						"id": 'login_weixin',
						"url": 'login_weixin.html',
						show: {
							aniShow: 'none'
						},
						waiting: {
							autoShow: true
						}
					});
				}, 100);
			}; */
			
			/* //TODO：通过settings.autoLogin直接进入主画面，必须先获取头像和用户名
			var mainPage = plus.webview.getWebviewById("main");
			var main_loaded_flag = false;
			if (!mainPage) {
				mainPage = mui.preload({
					"id": 'main',
					"url": 'main.html'
				});
			} else {
				main_loaded_flag = true;
			}

			mainPage.addEventListener("loaded", function () {
				main_loaded_flag = true;
			});
			var toMain = function () {
				//使用定时器的原因：
				//可能执行太快，main页面loaded事件尚未触发就执行自定义事件，此时必然会失败
				var id = setInterval(function () {
					if (main_loaded_flag) {
						clearInterval(id);
						mui.fire(mainPage, 'show', null);
						mainPage.show("pop-in");
					}
				}, 20);
			}; */

			//检查 "登录状态/锁屏状态" 开始
			if (settings.autoLogin && state.token && settings.gestures) {
				/*mui.openWindow({
					url: 'unlock.html',
					id: 'unlock',
					show: {
						aniShow: 'pop-in'
					},
					waiting: {
						autoShow: false
					}
				});*/
			} else if (settings.autoLogin && state.token) {
				//toMain();
			} else {
				app.setState(null);
				document.getElementById('wxLogin').addEventListener('tap', function () {
					var auths = {};
					plus.oauth.getServices(function (services) {
						auths = services;
						var auth;
						for (var i = 0; i < auths.length; i++) {
							if (auths[i].id == "weixin") {
								auth = auths[i];
								if (!auth.authResult) {
									auth.login(function (e) {
										plus.nativeUI.toast("登录认证成功");
										auth.getUserInfo(function (e) {
											//plus.nativeUI.toast("获取用户信息成功："+JSON.stringify(auth.userInfo) );
											var josnStr = JSON.stringify(auth.userInfo);
											var jsonObj = auth.userInfo;
											var name = auth.userInfo.nickname || auth.userInfo.name;
											var headimgurl = auth.userInfo.headimgurl;
											plus.storage.setItem("name", name);
											plus.storage.setItem("headimgurl", headimgurl);
											//plus.storage.setItem("province", auth.userInfo.province);
											//plus.storage.setItem("city", auth.userInfo.city);
											//根据code获取uid（code对应表里的uid字段，uid对应表里的id字段）
											var userid = auth.userInfo.unionid;
											//console.log("userid of login.html: "+userid);
											plus.storage.setItem("userid", userid);
											clicked("login_weixin.html", true, {
												"mid": "通过extras传递数据"
											});
											//toWxPage();
										}, function (e) {
											plus.nativeUI.toast("获取用户信息失败：" + e.message + " - " + e.code);
										});
									}, function (e) {
										plus.nativeUI.toast("登录认证失败：" + e.message + " - " + e.code);
									});
								} else {
									plus.nativeUI.toast("已经登录认证");
									auth.getUserInfo(function (e) {
										//plus.nativeUI.toast("获取用户信息成功："+JSON.stringify(auth.userInfo) );
										var josnStr = JSON.stringify(auth.userInfo);
										var jsonObj = auth.userInfo;
										var name = auth.userInfo.nickname || auth.userInfo.name;
										var headimgurl = auth.userInfo.headimgurl;
										plus.storage.setItem("name", name);
										plus.storage.setItem("headimgurl", headimgurl);
										//plus.storage.setItem("province", auth.userInfo.province);
										//plus.storage.setItem("city", auth.userInfo.city);
										//根据code获取uid（code对应表里的uid字段，uid对应表里的id字段）
										var userid = auth.userInfo.unionid;
										//console.log("已经登录认证userid of login.html: " + userid);
										clicked("login_weixin.html", true, {
											"mid": "通过extras传递数据"
										});
										//toWxPage();
									}, function (e) {
										plus.nativeUI.toast("获取用户信息失败：" + e.message + " - " + e.code);
									});
								}
							}
						}
					}, function (e) {
						plus.nativeUI.toast("获取登录服务列表失败：" + e.message + " - " + e.code);
					});
				});

				document.getElementById('mbLogin').addEventListener('tap', function () {
					clicked("login_mobile.html", true, {
						"mid": "通过extras传递数据"
					});
				});

				document.getElementById('fuwu').addEventListener('tap', function () {
					document.getElementById('polcontent').value = "服务许可协议";
					document.getElementById('policy').hidden = !document.getElementById('policy').hidden;
				});

				document.getElementById('yinsi').addEventListener('tap', function () {
					document.getElementById('polcontent').value = "隐私政策";
					document.getElementById('policy').hidden = !document.getElementById('policy').hidden;
				});
			}

			var backButtonPress = 0;
			mui.back = function (event) {
				backButtonPress++;
				if (backButtonPress > 1) {
					plus.runtime.quit();
				} else {
					plus.nativeUI.toast('再按一次退出应用');
				}
				setTimeout(function () {
					backButtonPress = 0;
				}, 1000);
				return false;
			};
		});

		// 设置启动时的轮播页
		/* function launchScreen() {
			var showGuide = plus.storage.getItem("lauchFlag");  //读取本地存储，检查是否为首次启动
			if (showGuide) {  //有值，说明已经显示过了，无需显示
				//关闭splash页面；
				setTimeout(function () {
					plus.navigator.closeSplashscreen();
					plus.navigator.setFullscreen(false);
				}, 200);
			} else {  //无值，说明是首次启动，显示启动导航
				plus.navigator.closeSplashscreen();
				plus.navigator.setFullscreen(true);
				mui.openWindow({
					id: 'guide',
					url: 'guide.html',
					show: {
						aniShow: 'none'
					},
					waiting: {
						autoShow: false
					}
				});
			}
		} */
	</script>
</body>

</html>